package cn.xuanxuanyuhua.crm.web.controller;

import cn.xuanxuanyuhua.crm.domain.CustomerTraceHistory;
import cn.xuanxuanyuhua.crm.domain.Employee;
import cn.xuanxuanyuhua.crm.query.CustomerTraceHistoryQueryObject;
import cn.xuanxuanyuhua.crm.service.ICustomerTraceHistoryService;
import cn.xuanxuanyuhua.crm.service.ISystemDictionaryService;
import cn.xuanxuanyuhua.crm.util.DateUtil;
import cn.xuanxuanyuhua.crm.util.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/customerTraceHistory")
public class CustomerTraceHistoryController {

    @Autowired
    private ICustomerTraceHistoryService service;
    @Autowired
    private ISystemDictionaryService dictService;

    @RequestMapping("/list")
    public String list(Model m,@ModelAttribute("qo")CustomerTraceHistoryQueryObject qo){
        if (!UserContext.isAdminAndMgr()) {
            qo.setSellerId(UserContext.getActiveUser().getId());
        }
        qo.setOrderBy("history.inputTime desc");
        m.addAttribute("pageInfo",service.query(qo));
        m.addAttribute("types",dictService.selectAllBySn("communicationMethod"));
        return "/customerTraceHistory/list";
    }

    @RequestMapping("/saveOrUpdate")
    public String  saveOrUpdate(CustomerTraceHistory entity){
        service.saveOrUpdate(entity);
        return "redirect:/customerTraceHistory/list.do";
    }


}
